﻿using System;
using System.IO;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;
using WpfHero;

namespace Tutorial
{
	public partial class SongScroller
	{
	    private WHEngine _engine;

		public SongScroller()
		{
		    DataContextChanged += delegate { _engine = (WHEngine) DataContext; };
			this.InitializeComponent();

			// Insert code required on object creation below this point.
		}

	    private DoubleAnimation scrollAnimation = null;
        public void Start()
        {
            App.DoEvents();
            DoubleAnimation scrollAnimation = new DoubleAnimation
                                     {
                                         From = 0,
                                         To = (grid.ActualWidth * -1) + stackPanel.Margin.Left,
                                         Duration = new Duration(_engine.EndOfSong)
                                     };

            stackPanel.RenderTransform = new TranslateTransform();
            stackPanel.RenderTransform.BeginAnimation(TranslateTransform.XProperty, scrollAnimation);
        }

        public void Stop()
        {
            stackPanel.RenderTransform = new TranslateTransform();
            App.DoEvents();
        }
	}
}